<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    <script src="./lib/axios.min.js"></script>-->
      <script src="./lib/zhang.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script>
    let cancelHandler = null;
	const btns = document.querySelectorAll("button");

	btns[0].onclick = async function () {
		try{
			const response = await axios.get("http://zhangpeiyue.com/scoreList",{
				// {cancel:Promise实例-状态为pending,值undefined}
				cancelToken:new axios.CancelToken(function(cancel){
					// cancelHandler---->resolve
					cancelHandler = cancel;
				})
			});
			console.log(response);
		}catch (err){
			console.log("err",err)
        }

	}
	btns[1].onclick = function(){
		if(cancelHandler) cancelHandler();
    }
</script>
</html>